import { z } from "zod";

import { type getBlogListMapper } from "../sql";
import { PUBLISH_KAY } from "@/types/enum";

export const verifyCreateBlog = z.object({
  title: z.string().min(1, { message: "长度不能少于1个字符" }),
  description: z.string().min(1, { message: "长度不能少于1个字符" }),
  cover: z.string().nullable().optional(),
  content: z.string().min(1, { message: "长度不能少于1个字符" }),
  published: z.boolean().optional(),
  tags: z.string().array().optional(),
});

export const verifyUpdateBlog = verifyCreateBlog.partial().extend({
  id: z.string().min(1),
});

export const verifyGetBlogList = z.object({
  title: z.string().optional(),
  tags: z.string().array().optional(),
  published: z
    .enum([PUBLISH_KAY.ALL, PUBLISH_KAY.PUBLISHED, PUBLISH_KAY.UNPUBLISHED])
    .optional(),
  pageIndex: z.number(),
  pageSize: z.number(),
});

export type CreateBlogDTO = z.infer<typeof verifyCreateBlog>;
export type UpdateBlogDTO = z.infer<typeof verifyUpdateBlog>;
export type GetBlogListDTO = z.infer<typeof verifyGetBlogList>;

export type Blog = Awaited<
  ReturnType<typeof getBlogListMapper>
>["blogs"][number];
